from rest_framework import serializers

from common.models import TbStrategyComment
from common.models import TbStrategy
from common.models import TbScenic
from common.models import TbCollection, TbBrowseHistory
from common.models import TbStory, TbStoryImg
from common.models import TbStyImg
from common.models import TbCity, TbSenicStratery


class TbStrategyCommentSerializer(serializers.ModelSerializer):
    """评论模型的序列化类"""
    # tbcomment_set = serializers.StringRelatedField(many=True)

    class Meta:
        model = TbStrategyComment
        fields = '__all__'


class TbStrategySerializerDetail(serializers.ModelSerializer):
    """攻略详情模型的徐序列化"""
    tbstyimg_set = serializers.StringRelatedField(many=True)
    tbsenicstratery_set = serializers.StringRelatedField(many=True)
    # tbstrategycomment_set = serializers.StringRelatedField(many=True)

    class Meta:
        model = TbStrategy
        fields = ('content', 'id', 'tbstyimg_set', 'tbsenicstratery_set')


class TbSenicStraterySerializer(serializers.ModelSerializer):
    """序列化 攻略  经典 模型序列化"""
    # strategy = TbStoryCommentSerializer(TbStrategy.objects.all(), many=True)

    class Meta:
        model = TbSenicStratery
        fields = '__all__'


class CollectionSerializer(serializers.ModelSerializer):
    """收藏序列化类"""
    class Meta:
        model = TbCollection
        fields = ('create_time', 'type', 'article_id', 'title')


class TbImageSeriializer(serializers.ModelSerializer):
    """攻略图片模型的序列化"""
    strategy = TbStrategySerializerDetail(TbStrategy.objects.all(), many=True)

    class Meta:
        model = TbStyImg
        fields = ('url', )


class TbStrategySerializerHot(serializers.ModelSerializer):
    """返回 攻略top5 的序列化类"""
    # image = TbImageSeriializer(many=True, read_only=True)
    # tbstyimg_set = serializers.StringRelatedField(many=True)

    class Meta:
        model = TbStrategy
        fields = '__all__'


class ScenicSerializer(serializers.ModelSerializer):
    class Meta:
        # 指定序列化模型
        model = TbScenic
        fields = '__all__'


class BrowseHistorySerializer(serializers.ModelSerializer):
    """浏览历史序列化类"""
    class Meta:
        model = TbBrowseHistory
        fields = ('uid', 'type', 'hostory_id', 'title')


class TbCitySerializer(serializers.ModelSerializer):
    """城市模型序列化"""
    class Meta:
        model = TbCity
        fields = '__all__'


class TbStraregySerializerCity(serializers.ModelSerializer):
    """城市去联系攻略 模型序列化"""
    # dity = TbCitySerializer(TbCity.objects.all(), many=True)

    class Meta:
        model = TbStrategy
        fields = '__all__'


class TbStraregySerializerList(serializers.ModelSerializer):
    """序列化返回List, Create返回的字段"""
    strategy = TbStrategySerializerDetail(TbStrategy.objects.all(), many=True, read_only=True)

    class Meta:
        model = TbStrategy
        fields = '__all__'


class ScenicdetailSerializer(serializers.ModelSerializer):
    class Meta:
        model = TbScenic
        fields = ('name', 'intro')


class SerializerStoryImg(serializers.ModelSerializer):
    """
    StoryImage的序列化类
    """
    class Meta:
        model = TbStoryImg
        fields = ('name', 'url', 'story')


class SerializerStory(serializers.ModelSerializer):
    """
    Story的序列化器
    """
    img = SerializerStoryImg(many=True, read_only=True)

    class Meta:
        model = TbStory
        fields = '__all__'
